'''
Created on 2 Jan 2010

@author: ai
'''

import cPickle as pickle
import base64

class AVD(object):    
    """ Wrapper around an AVD, whose details are outputted from
    'android list avd'.
    
    e.g.:
    Available Android Virtual Devices:
    Name: 1.5_HVGA
    Path: C:\Users\ai\.android\avd\1.5_HVGA.avd
    Target: Android 1.5 (API level 3)
    Skin: HVGA    
    """
    
    def __init__(self, name, path, target, skin, sdcard=None):
        self.name = name
        self.path = path
        self.target = target
        self.skin = skin
        self.sdcard = sdcard
        
    def __cmp__(self, other):
        """ Two AVD objects are identical if all their member variables are
        identical.
        """
        if all(getattr(self, elem) == getattr(other, elem) for elem in ["name", "path", "target", "skin", "sdcard"]):
            return 0
        return -1 
    
    @staticmethod
    def convert_to_str(obj):
        return base64.b64encode((pickle.dumps(obj, -1)))
    
    @staticmethod
    def convert_from_str(s):
        return pickle.loads(base64.b64decode(s))